package fy.test;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import fy.util.DBUtil; 

  

public class ToUnicode{ 
	//private final static String sql="select t1.field0012,t1.field0002,t2.field0045,t3.field0035,t3.field0038 from formmain_3060 t1 join formson_3063 t2 on t1.id=t2.formmain_id join formson_3061 t3 on t1.id=t3.formmain_id where t1.field0012=? AND field0002='福耀玻璃工业集团股份有限公司（总办）'";
	private final static String sql="SELECT r.name FROM ORG_MEMBER r WHERE r.code=?";
	
	void f() throws IOException { 
  
    	Connection conn = null;
		PreparedStatement pst = null;
		ResultSet rs = null;
		String consult_no=null;
		StringBuffer unicode = new StringBuffer();
                    try {
                    	conn=connect("oracle.jdbc.driver.OracleDriver", "jdbc:oracle:thin:@10.112.0.170:1521:oatest", "v3xuser", "fyoa2009");
        				pst=conn.prepareStatement(sql);
        	         pst.setString(1,"084474");
        				rs = pst.executeQuery();
        				if (rs.next()) {
        				 consult_no = rs.getString(1);
        					System.out.println(consult_no+'\n');
        				}
        				
        				  
        				System.out.println(string2Unicode(consult_no));
        				    
        				System.out.println(unicode2String(string2Unicode(consult_no)));
        				   
        				  
        			} catch (Exception e) {
        				e.printStackTrace();
        			}finally{
        				DBUtil.close(rs, pst);}
                    
                    // 转换为unicode
                
        	//		}
                  

          //  } 

           // line = br.readLine(); 

      //  } 

       // br.close(); 

    } 

	public static Connection connect(String driverClassName, String url,
			String userName, String password) throws Exception {

		Class.forName(driverClassName);
		DriverManager.setLoginTimeout(60);
		return DriverManager.getConnection(url, userName, password);
	}
	/**
	  * 字符串转换unicode
	  */
	 public static String string2Unicode(String string) {
	  
	     StringBuffer unicode = new StringBuffer();
	  
	     for (int i = 0; i < string.length(); i++) {
	  
	         // 取出每一个字符
	        char c = string.charAt(i);
	  
	         // 转换为unicode
	         unicode.append("\\u" + Integer.toHexString(c));
	     }
	  
	     return unicode.toString();
	 }

	 /**
	  * unicode 转字符串
	 */
	public static String unicode2String(String unicode) {
	  
	     StringBuffer string = new StringBuffer();
	  
	     String[] hex = unicode.split("\\\\u");
	  
	     for (int i = 1; i < hex.length; i++) {
	  
	         // 转换出每一个代码点
	        int data = Integer.parseInt(hex[i], 16);
	  
	         // 追加成string
	         string.append((char) data);
	     }
	  
	     return string.toString();
	 }
    public static void main(String[] args) { 

        ToUnicode o = new ToUnicode(); 

        try { 

            o.f(); 

        } catch (IOException e) { 


            e.printStackTrace(); 

        } 

    } 

}